package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/3 17:05
 * @description
 */
public class Code442 {
    public List<Integer> findDuplicates(int[] nums) {
        List<Integer> result = new ArrayList<>();
        String numStr = Arrays.toString(nums);
        numStr = numStr.replace("]", ",]").replace("[", "[ ");
        for (int i = 0; i < nums.length; i++) {
            if (numStr.split(" " + nums[i] + ",").length == 3) {
                if (!result.contains(nums[i])) {
                    result.add(nums[i]);
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int nums[] = {10, 2, 5, 10, 9, 1, 1, 4, 3, 7};
        System.out.println(new Code442().findDuplicates(nums));
    }
}
